package com.snake.springboot.authority.web.controller;

import com.snake.springboot.authority.api.model.AuthSysAdminModel;
import com.snake.springboot.authority.api.request.AuthSysAdminChangeReq;
import com.snake.springboot.authority.api.request.AuthSysAdminQuery;
import com.snake.springboot.authority.api.service.AuthSysAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.result.ReturnList;
import org.snake.common.validate.Create;
import org.snake.common.validate.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类 {@code AuthSysAdminController}  <br> .
 * <p>权限管理-系统管理员控制器
 * <p>创建时间：2025/01/14
 *
 * @author Huang.yj
 */
@Api(tags = "权限管理-系统管理员")
@RestController
@RequestMapping("/auth/system-admin")
public class AuthSysAdminController {

    private AuthSysAdminService authSysAdminService;

    @Autowired
    public AuthSysAdminController(AuthSysAdminService authSysAdminService){
        this.authSysAdminService = authSysAdminService;
    }

    @ApiOperation("添加系统管理员")
    @PostMapping("/add")
    public ResponseResult<AuthSysAdminModel> addSystemAdmin(
            @ApiParam(name = "系统管理员入参", value = "传入json格式", required = true)
            @RequestBody @Validated(Create.class) AuthSysAdminModel model) throws Exception{
        AuthSysAdminModel result = authSysAdminService.addSystemAdmin(model);
        return ResponseResultFactory.ucc("添加成功",result);
    }

    @ApiOperation("修改系统管理员")
    @PostMapping("/modify")
    public ResponseResult<AuthSysAdminModel> modifySystemAdmin(
            @ApiParam(name = "系统管理员入参", value = "传入json格式", required = true)
            @RequestBody @Validated(Update.class) AuthSysAdminModel model) throws Exception {
        AuthSysAdminModel result = authSysAdminService.modifySystemAdmin(model);
        return ResponseResultFactory.ucc("修改成功",result);
    }

    @ApiOperation("移除系统管理员")
    @GetMapping("/remove/{sysadminid}")
    public ResponseResult<Object> removeSystemAdmin(
            @ApiParam(name = "系统管理员ID", value = "传入string格式", required = true)
            @PathVariable("sysadminid") String sysAdminId) throws Exception {
        authSysAdminService.removeSystemAdmin(sysAdminId);
        return ResponseResultFactory.ucc("移除成功");
    }

    @ApiOperation("修改可用状态")
    @PostMapping("/change_enable")
    public ResponseResult<Object> changeEnable(
            @ApiParam(name = "系统管理员入参", value = "传入json格式", required = true)
            @RequestBody AuthSysAdminModel model) throws Exception{
        authSysAdminService.changeEnable(model);
        return ResponseResultFactory.ucc("修改成功");
    }

    @ApiOperation("修改默认标识")
    @PostMapping("/change_default_flag")
    public ResponseResult<Object> changeDefaultFlag(
            @ApiParam(name = "系统管理员入参", value = "传入json格式", required = true)
            @RequestBody AuthSysAdminModel model) throws Exception {
        authSysAdminService.changeDefaultFlag(model);
        return ResponseResultFactory.ucc("修改成功");
    }

    @ApiOperation("修改密码")
    @PostMapping("/change_password")
    public ResponseResult<Object> changePassword(
            @ApiParam(name = "修改密码入参", value = "传入json格式", required = true)
            @RequestBody @Validated AuthSysAdminChangeReq params) throws Exception {
        authSysAdminService.changePassword(params);
        return ResponseResultFactory.ucc("修改成功");
    }

    @ApiOperation("查询系统管理员")
    @GetMapping("/query/{sysadminid}")
    public ResponseResult<AuthSysAdminModel> querySingleSystemAdmin(
            @ApiParam(name = "系统管理员ID", value = "传入string格式", required = true)
            @PathVariable("sysadminid") String sysAdminId) {
        AuthSysAdminModel result = authSysAdminService.querySingleSystemAdmin(sysAdminId);
        return ResponseResultFactory.ucc("查询成功",result);
    }

    @ApiOperation("查询系统管理员列表")
    @PostMapping("/list")
    public ResponseResult<List<AuthSysAdminModel>> querySystemAdminList(
            @ApiParam(name = "系统管理员入参", value = "传入json格式", required = true)
            @RequestBody AuthSysAdminModel params) {
        List<AuthSysAdminModel> result = authSysAdminService.querySystemAdminList(params);
        return ResponseResultFactory.ucc("查询成功",result);
    }

    @ApiOperation("分页查询系统管理员列表")
    @PostMapping("/page_list")
    public ResponseResult<ReturnList<AuthSysAdminModel>> querySystemAdminList(
            @ApiParam(name = "系统管理员分页查询入参", value = "传入json格式", required = true)
            @RequestBody AuthSysAdminQuery query) {
        ReturnList<AuthSysAdminModel> result = authSysAdminService.querySystemAdminList(query);
        return ResponseResultFactory.ucc("查询成功",result);
    }
}
